/* 
 * Page frame allocator 4k
 *
 */

#include "println.h"
#include "unistd.h"

extern unsigned int endkernel;

#define MAX 1024
#define FREE 0x00
#define USED 0x01


int pages_map[MAX];
unsigned int pages[MAX];


void init_pages_map(){

	int i;

	for(i=0; i<MAX; i++) 
		pages_map[i] = FREE;

}


int find_pages() {

	int i;

	for(i=0; i<MAX; i++) 		
		if(pages_map[i] == FREE)
			return(i);				

	printLine("error - pagining");

} 


void *alloc_pages() {

	int i = find_pages();
	pages_map[i] = USED;
	
	return(endkernel + (i*0x1000));
}


void free_pages(int i) {

	pages_map[i] = FREE;
	
}









